<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/control/city_linkage/css/city-picker.css')}}"/>
    <link rel="stylesheet" href="{{asset('/css/web/user/pw_revise.css')}}">
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.seller_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">邀请员工</div>
                <div class="revise_subnav">
                    <ul>
                        <li>验证身份</li>
                        <li class="cur">修改验证手机</li>
                        <li>完成</li>
                    </ul>
                </div>
                <div class="revise_content">
                    <div class="box">
                        <form action="{{url('/member/seller/member/create3')}}" method="post" onsubmit="return frm_data_check();" id="js-frm-pwrevise">
                            <ul>
                                <li>
                                    <span>手机号码：</span>
                                    <p class="se" style="border:0;">{{$phone}}</p>
                                </li>
                                <li>
                                    <span>邀请码：</span>
                                    <input name='code' id='code' type="text" class="yzm getborder" placeholder="请输入邀请码">
                                    <p class="jm_error"></p>
                                    <a id='send_code' href="javascript:;" class="getmess j-validate-code">获取邀请码</a>
                                </li>
                                <input type="hidden" name="_token" value="{{csrf_token()}}" />
                                <input name='phone' id='phone' type="hidden" value="{{$phone}}" class="se getborder" />
                            </ul>
                            <input type="submit" class="jm_btn6 submit" value="下一步" />
                        </form>
                    </div>
                    <div class="j-err" style="margin-left:312px; margin-top: 32px; color: red; font-size: large;"></div>
                </div>
            </div>
        </div>
    </div>
</div>
@include('web.layout.footer')
</body>
<script>
    $(function () {
        $('.j-validate-code').click(function () {
            var _url = "{{URL('user/sendmessages')}}";
            var $this = $(this).parents('ul'),
                    _phone = $this.find("input[name='phone']"),
                    _token = $this.find("input[name='_token']").val();
            $.get(_url, {phone: _phone.val(), _token: _token}, function(res){
                if(res.code == '0'){
                    layer.alert('验证码已发送，请注意查收');
                } else {
                    _phone.parent().find('.jm_error').html(res.message);
                }
            }, 'json');
        })
    })
    function frm_data_check() {
        var _frm = $('#js-frm-pwrevise');
        var _phone = _frm.find('input[name="phone"]'), _code = _frm.find('input[name="code"]');
        if (_code.val() == '') {
            _code.parent().find('.jm_error').html('邀请码 必须填写');
            return false;
        }
        var _url = '/member/seller/member/verifyCode';
        var flag = false;
        // 校验短信验证码
        $.ajax({
            url: _url,
            data:{phone: _phone.val(),code:_code.val(), _token:"{{csrf_token()}}"},
            type:'POST',
            async:false,
            success:function (res) {
                if (res.code != 0) {
                    _phone.parent().find('.jm_error').html(res.message);
                    return false;
                } else {
                    flag = true;
                }
            },
            error:function (error) {
                _phone.parent().find('.jm_error').html(error.message);
                return false;
            }
        });
        // 假设验证码存在，让系统先走下去。
        if (flag==false){
            return false;
        }
    }
</script>
</html>